from rest_framework import serializers
from .models import NavInfo,ZhangjieInfo,FictionInfo,TextInfo

class Zhangjieserializer(serializers.ModelSerializer):
    class Meta:
        model = ZhangjieInfo
        fields='__all__'

class Fictionserializer(serializers.ModelSerializer):#小说的序列化携带者最新章节
    navid = serializers.SlugRelatedField(slug_field='name',read_only=True)
    new_zhang = serializers.SerializerMethodField()
    def get_new_zhang(self,obj):
        new_z = ZhangjieInfo.objects.filter(fiction_id=obj.id).order_by('-id')[:1]
        new_zhang = Zhangjieserializer(new_z,many=True,context={'request': self.context['request']})
        return new_zhang.data


    class Meta:
        model = FictionInfo
        fields='__all__'


class Navserializer(serializers.ModelSerializer):

    class Meta:
        model = NavInfo
        fields='__all__'



class TextSerialziers(serializers.ModelSerializer):
    class Meta:
        model = TextInfo
        fields='__all__'